package app.server.project.main.service.db.entity.user;

import app.server.project.core.syndb.SynDBMgr;
import app.server.project.core.syndb.SynSpeed;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Transient;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.time.LocalDateTime;

@Data
@Entity(name = "user_ton_order")
@TableName("user_ton_order")
@Comment(value = "用户ton订单明细消息")
@SynSpeed
public class OrderDetailEntity {


    @Id
    @Column(name = "order_id")
    @Comment("订单主键")
    @TableId("order_id")
    private long orderId;

    @TableField("ton_hash")
    @Comment("hash码")
    @Column(name = "ton_hash", length = 600)
    private String tonHash;


    @TableField("wallet_address")
    @Comment("钱包地址")
    @Column(name = "wallet_address")
    private String walletAddress;

    @TableField("flush_time")
    @Comment("更新时间")
    @Column(name = "flush_time")
    private LocalDateTime flushTime;


    @TableField("fail_des")
    @Comment("支付失败描述")
    @Column(name = "fail_des", length = Integer.MAX_VALUE)
    private String failDes;

    @Transient
    @TableField(exist = false)
    private boolean synDb = false;

    public static OrderDetailEntity of(long orderId) {
        var ret = new OrderDetailEntity();
        ret.setSynDb(true);
        ret.setOrderId(orderId);
        ret.setFlushTime(LocalDateTime.now());
        return ret;
    }

    public void setFailDes(String failDes) {
        this.failDes = failDes;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(OrderDetailEntity::getFailDes, this);
    }

    public void setTonHash(String tonHash) {
        this.tonHash = tonHash;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(OrderDetailEntity::getTonHash, this);
    }

    public void setWalletAddress(String walletAddress) {
        this.walletAddress = walletAddress;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(OrderDetailEntity::getWalletAddress, this);
    }

    public void setFlushTime(LocalDateTime flushTime) {
        this.flushTime = flushTime;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(OrderDetailEntity::getFlushTime, this);
    }


}
